var Adv_skd=require("./Adv_skd")
var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2Hts = require("Hts");
var $2WeChatConstant = require("WeChatConstant");
var $2ADManager = require("ADManager");
var $2GameSwitch = require("GameSwitch");
var $2AudioManager = require("AudioManager");
var $2BundleManager = require("BundleManager");
var $2DataManager = require("DataManager");
var $2ExcelManager = require("ExcelManager");
var $2UserDataManager = require("UserDataManager");
var $2GameManager = require("GameManager");
var $2pvzChannel = require("pvzChannel");
var $2kc = require("kc");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
cc.macro.CLEANUP_IMAGE_CACHE = false;
cc.dynamicAtlasManager.maxFrameSize = 512;
cc.dynamicAtlasManager.enabled = true;
var def_LoadScene = /* */function (_cc$Component43) {
  babel_inherits(C, _cc$Component43);
  var _super47 = babel_createSuper(C);
  function C() {
    var _this100;
    babel_classCallCheck(this, C);
    _this100 = _super47.apply(this, arguments);
    _this100.progress = null;
    _this100.loading = null;
    _this100.jkgg = null;
    _this100.num = null;
    _this100.step = -1;
    _this100.bundleCount = 2;
    _this100.bundleLoad = 0;
    _this100.preloadCount = 18;
    _this100.preloadFinish = 0;
    _this100.progressNumber1 = 0;
    _this100.progressNumber2 = 0;
    _this100.progressNumber3 = 0;
    _this100.progressNumber4 = 0;
    _this100.length = 0;
    _this100.sltx = null;
    _this100.sltx_tips = null;
    _this100.mask = null;
    return _this100;
  }
  babel_createClass(C, [{
    key: "onLoad",
    value: function onLoad() {
      Adv_skd.default.instance.getWxIdFromServer(()=>{
var _this101 = this;
      $2GameManager.default.instance.changeOrientation();
      this.sltx = cc.find("sltx", this.node);
      this.mask = cc.find("sltx_tips/mask", this.node);
      this.sltx_tips = cc.find("sltx_tips", this.node);
      this.sltx_tips.active = false;
      this.sltx.on(cc.Node.EventType.TOUCH_START, this.on_slts, this);
      this.mask.on(cc.Node.EventType.TOUCH_START, this.on_slts_tips, this);
      cc.director.getCollisionManager().enabled = true;
      $2kc.default.init();
      $2ADManager.default.instance.init();
      $2pvzChannel.pvzChannel.instance().init();
      this.str = "加载中......";
      this.jkgg.string += $2pvzChannel.pvzChannel.instance().getRuanZhu();
      this.initUserData();
      if ("wx2" !== $2pvzChannel.pvzChannel.instance().channel) {
        this.toNormalMode();
      } else {
        var _e49 = {
          id: $2pvzChannel.pvzChannel.instance().getPara("ctrlId")
        };
        $2kc.default.jpost("https://ga.gametdd.com/adCtrl/agd/conf", _e49, function (e, t) {
          if (e) {
            $2kc.default.err(e);
          } else {
            $2kc.default.log("返回", t);
            if ("" + t.code != "0") {
              $2kc.default.err("返回值错误:" + JSON.stringify(t));
              return void _this101.toNormalMode();
            }
            $2pvzChannel.pvzChannel.instance().getChannel().ctrl = t.data;
            if ("1" === t.data.p10) {
              _this101.loadJjdfGame();
            } else {
              _this101.toNormalMode();
            }
          }
        });
      }
      })
      
    }
  }, {
    key: "loadJjdfGame",
    value: function loadJjdfGame() {

      $2kc.default.log("准备进入JjdfGame!!!");
      var e = this;
      cc.assetManager.loadBundle("Jiujiudaifu", function (t, a) {
        if (t) {
          console.error("Jiujiudaifu加载失败", t);
        } else {
          a.loadDir("./", cc.Prefab, function (t, a) {
            var n = t / a;
            e.progress.progress = n;
            e.num.string = Math.ceil(100 * n) + "%";
            e.progress.node.getChildByName("j001").x = 1200 * n;
          }, function () {
            a.load("time", cc.TextAsset, function (t, n) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.timeTable, n.text);
              a.load("JiujiudaifuUI", cc.Prefab, function (t, a) {
                if (t) {
                  console.error("JiujiudaifuUI加载失败", t);
                } else {
                  cc.instantiate(a).parent = e.node;
                }
              });
            });
          });
        }
      });
    }
  }, {
    key: "loadDfGame",
    value: function loadDfGame() {
        var _this102 = this;
        $2kc.default.log("准备进入dfGame!!!");
        cc.assetManager.loadBundle("Dfbwzh", function (e, t) {
          if (e) {
            console.error("Dfbwzh加载失败", e);
          } else {
            t.loadDir("./", cc.Prefab, function (e, t) {
              var a = e / t;
              _this102.progress.progress = a;
              _this102.num.string = Math.ceil(100 * a) + "%";
              _this102.progress.node.getChildByName("j001").x = 1200 * a;
            }, function () {
              t.load("bwzdaifu", cc.TextAsset, function (e, a) {
                $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.bwzdaifuTable, a.text);
                t.load("bwzjs", cc.TextAsset, function (e, a) {
                  $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.bwzjsTable, a.text);
                  t.load("DfbwzhUI", cc.Prefab, function (e, t) {
                    if (e) {
                      console.error("DfbwzhUI加载失败", e);
                    } else {
                      cc.instantiate(t).parent = _this102.node;
                    }
                  });
                });
              });
            });
          }
        });
    
    }
  }, {
    key: "toNormalMode",
    value: function toNormalMode() {
      var _this103 = this;
      $2GameSwitch.default.requestHttpGetGameSwitch();
      cc.director.preloadScene("MainScene");
      $2Hts.default.instance.init(undefined, function () {
        $2Hts.default.instance.eventReport("进入游戏");
        $2ADManager.default.instance.sdkType == $2ADManager.SDK_TYPE.WeChat && $2Hts.default.instance.bindOpenId($2WeChatConstant.default.openID, function () {});
      });
      this.nextStep();
      this.schedule(function () {
        _this103.length++;
        _this103.length = _this103.length % 6;
        _this103.loading.string = _this103.str.slice(0, _this103.length + 3);
      }, .5);
    }
  }, {
    key: "on_slts_tips",
    value: function on_slts_tips() {
      this.sltx_tips.active = false;
    }
  }, {
    key: "on_slts",
    value: function on_slts() {
      this.sltx_tips.active = true;
    }
  }, {
    key: "onClickAgePanel",
    value: function onClickAgePanel() {
      this.node.getChildByName("AgePanel").active = true;
    }
  }, {
    key: "nextStep",
    value: function nextStep() {
      var _this104 = this;
      this.step++;
      switch (this.step) {
        case 0:
          console.time("加载时间2");
          console.time("加载时间3");
          $2BundleManager.default.instance.loadBundle("BundleTexture").then(function () {
            $2BundleManager.default.instance.preLoadBundleDir("BundleTexture", "", cc.SpriteFrame, function (e) {
              _this104.progressNumber3 = e / 486;
              _this104.updateProgress();
            }, function () {
              console.timeEnd("加载时间2");
              _this104.nextStep();
            });
          });
          break;
        case 1:
          var _e50 = function _e50() {
            _this104.preloadFinish++;
            _this104.preloadCount == _this104.preloadFinish && _this104.nextStep();
          };
          $2BundleManager.default.instance.loadBundle("Audio").then(_e50);
          $2BundleManager.default.instance.loadBundle("Prefab").then(function () {
            $2BundleManager.default.instance.preLoadBundleDir("Prefab", "", cc.Prefab, function (e) {
              _this104.progressNumber2 = e / 2954;
              _this104.updateProgress();
            }, function () {
              console.timeEnd("加载时间3");
              _e50();
            });
          });
          $2BundleManager.default.instance.loadBundle("Data").then(function () {
            $2BundleManager.default.instance.loadBundleRes("Data", "./bullet", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.bulletTable, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./level", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.levelTable, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./plant", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.plantTable, a.text);
              $2ExcelManager.ExcelMgr.instance.AddExcelArrTable($2ExcelManager.TableName.plantTable, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./zombie", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.zombieTable, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./lottery", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.lotteryTable, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./shop", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.shopTable, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./price", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.priceTable, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./guide", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.guideTable, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./task", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.taskTable, a.text);
              _e50();
            });
            _e50();
            _e50();
            $2BundleManager.default.instance.loadBundleRes("Data", "./bwzjs", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.bwzjsTable, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./bwzdaifu", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.bwzdaifuTable, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./blq_zaxiang", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.blq_zaxiang, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./bxq_jianguo", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.bxq_jianguo, a.text);
              _e50();
            });
            $2BundleManager.default.instance.loadBundleRes("Data", "./blq_js", cc.TextAsset, function (t, a) {
              $2ExcelManager.ExcelMgr.instance.AddExcelTable($2ExcelManager.TableName.blq_js, a.text);
              _e50();
            });
          });
          break;
        case 2:
          cc.Button.prototype._onTouchEnded = function (e) {
            $2AudioManager.default.instance.playEffect("BtnClick");
            if (this.interactable && this.enabledInHierarchy) {
              if (this._pressed) {
                cc.Component.EventHandler.emitEvents(this.clickEvents, e), this.node.emit("click", this);
              }
              this._pressed = false;
              this._updateState();
              e.stopPropagation();
            }
          };
          this.nextStep();
          break;
        case 3:
          $2DataManager.default.instance.init();
          $2UserDataManager.default.instance.isNewDay();
          this.nextStep();
          break;
        default:
          if ("tt" !== $2pvzChannel.pvzChannel.instance().channel && "wx2" !== $2pvzChannel.pvzChannel.instance().channel && "wx7" !== $2pvzChannel.pvzChannel.instance().channel || 1 !== $2pvzChannel.pvzChannel.instance().getCtrl("p10")) {
            $2kc.default.log("进入主场景!!!!");
            if ($2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0) {
              var _e51 = $2pvzChannel.pvzChannel.instance().getCtrl("p8");
              _e51 && $2pvzChannel.pvzChannel.instance().startAdTimeCount(_e51, function () {
                $2pvzChannel.pvzChannel.instance().showVideo({
                  sucCall() {},
                  failCall() {},
                  endCall() {}
                });
              }, true);
            }
            cc.director.loadScene("MainScene");
          } else {
            this.loadJjdfGame();
          }
      }
    }
  }, {
    key: "updateProgress",
    value: function updateProgress() {
      var e = this.progressNumber2 + this.progressNumber3;
      this.progress.progress = e;
      this.num.string = Math.ceil(100 * e) + "%";
      this.progress.node.getChildByName("j001").x = 1200 * e;
    }
  }, {
    key: "initUserData",
    value: function initUserData() {
      var e = cc.sys.localStorage.getItem($2UserDataManager.default.instance._userDataKey);
      console.log("initUserData2222 本地数据====>>", typeof e);
      if (e) {
        console.log("本地数据====>>");
        $2UserDataManager.default.instance._userData = JSON.parse(String(e));
        $2UserDataManager.default.instance.is_new = false;
      } else {
        console.log("没有本地数据!");
        $2UserDataManager.default.instance.is_new = true;
        $2UserDataManager.default.instance.init();
        $2UserDataManager.default.instance.writeStorage();
      }
    }
  }]);
  return C;
}(cc.Component);
cc__decorate([ccp_property({
  type: cc.ProgressBar,
  displayName: "进度条"
})], def_LoadScene.prototype, "progress", undefined);
cc__decorate([ccp_property(cc.Label)], def_LoadScene.prototype, "loading", undefined);
cc__decorate([ccp_property(cc.Label)], def_LoadScene.prototype, "jkgg", undefined);
cc__decorate([ccp_property(cc.Label)], def_LoadScene.prototype, "num", undefined);
def_LoadScene = cc__decorate([ccp_ccclass], def_LoadScene);
exports.default = def_LoadScene;